package th.kmutt.se.is;

import android.R.menu;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;

public class Main extends FragmentActivity implements OnClickListener {

	private DrawerLayout drawerLayout;
	private LinearLayout drawer;
	private Button menuRooms, menuCharges, menuRecord;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.screen_main);

		init();
	}

	private void init() {
		drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
		drawer = (LinearLayout) findViewById(R.id.left_drawer);

		menuRooms = (Button) findViewById(R.id.menuRooms);
		menuCharges = (Button) findViewById(R.id.menuCharges);
		menuRecord = (Button) findViewById(R.id.menuRecord);
		menuRooms.setOnClickListener(this);
		menuCharges.setOnClickListener(this);
		menuRecord.setOnClickListener(this);

		selectItem(0);
	}

	private void selectItem(int position) {
		switch (position) {
			case 1: {
				Fragment fragment = new ChargesList();
				getSupportFragmentManager().beginTransaction()
						.replace(R.id.content_frame, fragment).commit();
				drawerLayout.closeDrawer(drawer);
			}break;
			case 2: {
				Fragment fragment = new RoomList();
				getSupportFragmentManager().beginTransaction()
						.replace(R.id.content_frame, fragment).commit();
				drawerLayout.closeDrawer(drawer);
			}break;
			case 0:
			default: {
				Fragment fragment = new RoomList();
				getSupportFragmentManager().beginTransaction()
						.replace(R.id.content_frame, fragment).commit();
				drawerLayout.closeDrawer(drawer);
			}break;
		}
	}

	public void openDrawer() {
		drawerLayout.openDrawer(drawer);
	}

	@Override
	public void setTitle(CharSequence title) {
		// mTitle = title;
		// getActionBar().setTitle(mTitle);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.menuRooms: {
			selectItem(0);
		}
			break;
		case R.id.menuCharges: {
			selectItem(1);
		}
			break;
		case R.id.menuRecord: {
			selectItem(2);
		}
			break;
		}
	}
}
